const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}

const {defineConfig} = require('@vue/cli-service');
module.exports = defineConfig({
  transpileDependencies: true
});

/* ElementUI 组件自动导入 */
const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
const {ElementPlusResolver} = require('unplugin-vue-components/resolvers');

module.exports = {

  configureWebpack: (config) => {
    /* ElementUI 组件自动导入 */
    config.plugins.push(AutoImport({
      resolvers: [ElementPlusResolver()]
    }));

    config.plugins.push(Components({
      resolvers: [ElementPlusResolver()]
    }));

    config.module.rules.push({
      test: /\.mjs$/,
      include: /node_modules/,
      type: "javascript/auto"
    });
  },


  chainWebpack: (config)=>{
    // 配置别名
    config.resolve.alias
      .set('@', resolve('src'))
      .set('assets',resolve('src/assets'))
      .set('components',resolve('src/components'))
      .set('router',resolve('src/router'))
      .set('utils',resolve('src/utils'))
      .set('static',resolve('src/static'))
      .set('store',resolve('src/store'))
      .set('views',resolve('src/views'))
      .set('network',resolve('src/network'))
  },

  // 解决本地开发环境的请求跨域问题
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:8081', //接口域名

        changeOrigin: true,             //是否跨域
        ws: true,                       //是否代理 websockets
        secure: true,                   //是否https接口
        pathRewrite: {                  //路径重置
          '^/api': ''
        }
      }
    },
  },




};


